// page/order/order.js
Page({
    data: {
        isHide: false,
        activeIndex: -1,
        items: [],
        showModalStatus: false,
        showFiltrate: false,
        px: '',
        pxopen: '',
        keywords: '',
        edu: '',
        is_night: '',
        point_min: '',
        point_max: '',
        pass_min: '',
        pass_max: '',
        p: 1,
        _edu: 0,
        _is_night: false,
        _pass_min: '',
        _pass_max: '',
        _point_min: '',
        _point_max: '',
        loadText: '加载更多',
        skeywords: '搜索关键字',
        duanziInfo: [],
        list: [],
        pass9: false,
        point8: false,
        //  pasn: false,
        //  poie:false,
        //  isHideLoadMore: false,
    },
    onLoad: function (options) {

    },
    bfocus: function (e) {
        this.setData(
            {
                skeywords: ''
            }
        );

    },
    powerDrawer: function (e) {

        var currentStatu = e.currentTarget.dataset.statu;
        if (currentStatu == 'open') {
            this.setData(
                {
                    pxopen: ''
                }
            );
            this.util(currentStatu)
            return false
        } else {
            this.util(currentStatu)
        }

        this.setData(
            {
                px: e.currentTarget.dataset.px,
                list: []
            }
        );
        this.getlist();
    },
    filtrateDrawer: function (e) {
        var currentStatu = e.currentTarget.dataset.statu;
        this.util(currentStatu)
    },
    updrawer: function (e) {
        var currentStatu = e.currentTarget.dataset.statu;
        this.utl(currentStatu)
    },
    resetInfo: function (e) {
        this.setData(
            {
                '_edu': '',
                '_is_night': false,
                '_point_min': '',
                '_point_max': '',
                '_pass_min': '',
                '_pass_max': '',
                'point8': false,
                'pass9': false,
            }
        );
    },
    downdrawer: function (e) {
        var currentStatu = e.currentTarget.dataset.statu;
        this.utl(currentStatu)
        this.setData(
            {
                'edu': this.data._edu,
                'is_night': this.data._is_night ? 1 : 0,
                'point_min': this.data.point8 ? 8 : this.data._point_min,
                'point_max': this.data.point8 ? '' : this.data._point_max,
                'pass_min': this.data.pass9 ? 90 : this.data._pass_min,
                'pass_max': this.data.pass9 ? '' : this.data._pass_max,
                'list': []
            }
        );
        this.getlist();
    },
    util: function (currentStatu) {
        /* 动画部分 */
        // 第1步：创建动画实例 
        var animation = wx.createAnimation({
            duration: 400, //动画时长 
            timingFunction: "ease", //线性 
            delay: 0 //0则不延迟 
        });
        // 第2步：这个动画实例赋给当前的动画实例 
        this.animation = animation;
        // 第3步：执行第一组动画 
        animation.translateY(-100+'%').step();
        // 第4步：导出动画对象赋给数据对象储存 
        this.setData({
            animationData: animation.export()
        })
        // 第5步：设置定时器到指定时候后，执行第二组动画 
        setTimeout(function () {
            // 执行第二组动画 
            animation.translateY(0).step();
            // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象 
            this.setData({
                animationData: animation
            })
            //关闭 
            if (currentStatu == "close") {
                this.setData(
                    {
                        showModalStatus: false
                    }
                );
            }
        }.bind(this), 0)
        // 显示 
        if (currentStatu == "open") {
            this.setData(
                {
                    showModalStatus: true,
                    showFiltrate: false
                }
            );
        }
    },
    // 筛选
    utl: function (currentStatu) {
        /* 动画部分 */
        // 第1步：创建动画实例 
        var animation = wx.createAnimation({
            duration: 400, //动画时长 
            timingFunction: "ease", //线性 
            delay: 0 //0则不延迟 
        });
        // 第2步：这个动画实例赋给当前的动画实例 
        this.animation = animation;
        // 第3步：执行第一组动画 
        animation.translateY(-100+'%').step();
        // 第4步：导出动画对象赋给数据对象储存 
        this.setData({
            animationData: animation.export()
        })
        // 第5步：设置定时器到指定时候后，执行第二组动画 
        setTimeout(function () {
            // 执行第二组动画 
            animation.translateY(0).step();
            // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象 
            this.setData({
                animationData: animation
            })
            //关闭 
            if (currentStatu == "close") {
                this.setData(
                    {
                        showFiltrate: false
                    }
                );
            }
        }.bind(this), 0)
        // 显示 
        if (currentStatu == "open") {
            this.setData(
                {
                    showFiltrate: true,
                    showModalStatus: false
                }
            );
        }
    },
    // 获取点击的条件内容
    onLoad: function (options) {
        options = options
    },
    onShow: function () {
        console.log(this.data)
        this.getlist();
    },
    cfkey: function (e) {
        this.setData({
            keywords: e.detail.value,
            list: []
        })
        this.getlist();
    },
    btnedu: function (e) {
        this.setData({
            _edu: e.currentTarget.dataset.edu
        })
        console.log(this.data.edu)
    },
    btneyj: function (e) {
        this.setData({
            _is_night: !this.data._is_night
        })
    },
    point: function (e) {
        this.setData({
            px: e.currentTarget.dataset.px,
            pxopen: 1,
            list: []
        })
        this.getlist();
    },
    inputnum1: function (e) {
        this.setData({
            _pass_min: e.detail.value
        })
    },
    inputnum2: function (e) {
        this.setData({
            _pass_max: e.detail.value
        })
    },
    inputnum3: function (e) {
        this.setData({
            _point_min: e.detail.value
        })
    },
    inputnum4: function (e) {
        this.setData({
            _point_max: e.detail.value
        })
    },
    pass_min90: function (e) {
        this.setData({
            pass9: !this.data.pass9,
        })
    },
    point_min8: function (e) {
        this.setData({
            point8: !this.data.point8,
        })
    },
    getlist: function () {
        var app = getApp()
        var that = this;
        var uid = wx.getStorageSync('uid');
        if (that.data.list.length == 0) that.data.p = 1;
        wx.request({
            url: app.globalData.host + '&g=App&m=Worker&a=index',
            data: {
                'uid': uid,
                'px': that.data.px,
                'keywords': that.data.keywords,
                'edu': that.data.edu,
                'is_night': that.data.is_night,
                'point_min': that.data.point_min,
                'point_max': that.data.point_max,
                'pass_min': that.data.pass_min,
                'pass_max': that.data.pass_max,
                'p': that.data.p,
                //  'p': 2,
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if (res.data.status == 1) {
                    var list = that.data.list
                    console.log(res.data.list)
                    console.log(res.data.list.length)
                    var ol = list.length
                    for (var i = 0; i < res.data.list.length; i++) {
                        list[ol + i] = res.data.list[i];
                    }
                    that.setData({
                        p: that.data.p + 1,
                        list: list,
                        // isHideLoad: true
                    })
                } else {
                    that.setData({
                        nodata: false,
                    })
                    console.log('--------暂无数据-------')
                }
                wx.hideNavigationBarLoading()
                // console.log(that.data)
            }
        })
        that.setData({
            isHide: 1,
        })

    },
    /**
     * 当前商品选中事件
     */
    selectList(e) {
        console.log(e)
        var that = this
        that.setData({
            activeIndex: e.currentTarget.dataset.id
        })
    },
    ordeid: function (e) {
        this.setData({
            id: e.currentTarget.dataset.id,
        })
        console.log(this.data.id)
    },
    skip: function (e) {
        var id = this.data.id
        var uid = wx.getStorageSync('uid');
        data: {
            id: this.data.id
            uid: uid
            // book_time: that.data.book_time;
            // book_date: that.data.book_date;
        }
        wx.navigateTo({
            url: '/page/coach/coach?id=' + id
        })
    },
    //加载更多 上拉
    onReachBottom: function () {
        console.log('--------下拉刷新-------')
        wx.showNavigationBarLoading() //在标题栏中显示加载
        this.getlist();

    },
    // 分享
    // onShareAppMessage: function (res) {
    //   var uid = wx.getStorageSync('uid');
    //   var that = this;
    //   var app = getApp()
    //   var scene = that.data.scene
    //   console.log(that.data.scene)
    //   if (res.from === 'button') {
    // 来自页面内转发按钮
    //   console.log(res.target)
    // }
    // return {
    //   title: '自定义转发标题',
    //   path: 'page/sign/sign?scene=scene',
    //   success: function (res) {
    // 转发成功
    //   wx.request({
    //     url: app.globalData.host + '&g=App&m=Index&a=feedback',
    //     data: {
    //       scene: scene
    //     },
    //     header: {
    //       'content-type': 'application/json'
    //     },
    //   })
    // },
    // fail: function (res) {
    // 转发失败
    //     }
    //   }
    // }
})